import React, { Component } from 'react'
import {ListBox} from '../../../components'

export default class ListResource extends Component {
    constructor(props) {
        super(props);

        //行操作列表
        this.rowOperation = [
            {
                handleName: 'cellEdit',
                iconClass: 'cellEdit'
            },{
                handleName: 'cellDele',
                iconClass: 'cellDele'
            },{
                handleName: 'cellDele1',
                iconClass: 'cellDele'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'addUser',
                showName: '新增'
            },{
                handleName: 'export',
                showName: '导出exce'
            }
        ];
    }
    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if(strHandles === 'cellEdit'){
            this.cellEditHandle(rowObj);
        }else if(strHandles === 'cellDele'){
            this.cellDeleHandle();
        }else if(strHandles === 'cellDele1'){
            this.lockUserHandle();
        }else if(strHandles === 'addUser'){
            this.addUserHandle();
        }else if(strHandles === 'export'){
            this.exportUserHandle();
        }
    }
    addUserHandle = () => {
        console.log("====执行了新增用户操作====");
    }
    exportUserHandle = () => {
        console.log("====执行了导出操作====");
    }

    cellEditHandle = (rowObj) => {
        console.log("====执行了修改操作====");
        console.log("rowObj======cellEditHandle========", JSON.stringify(rowObj));

        this.refs.listBox.pageNext();
        console.log("====刷新列表====");
    }

    cellDeleHandle = () => {
        console.log("=======执行了删除操作====");
    }

    lockUserHandle = () => {
        console.log("=======执行了锁定用户操作====");
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;
        let searchComponentData = [
          {
                showName: '资源名称',
                name:'resourceName',
                type: 'input',
                url: null
          },{
                showName: '资源类型',
                name:'resourceType',
                type: 'input',
                url: null
            },{
                showName: '是否可用',
                name:'activeFlag',
                type: 'input',
                url: null
            }
        ];
        //showName、columnName 必有属性， columnWidth 可选，默认100
        let tableColumn = [
            {
                showName: 'resourceId',
                columnName: 'resourceId'
            },{
                showName: '资源名称',
                columnName: 'resourceName',
                columnWidth: 130
            },{
                showName: 'href为空测试',
                columnName: 'href'
            },{
                showName: '资源类型',
                columnName: 'resourceType'
            },{
                showName: '创建人',
                columnName: 'createBy'
            },{
                showName: '创建时间',
                columnName: 'gmtCreate'
            },{
                showName: '是否可用',
                columnName: 'activeFlag'
            }
        ];
        return(
            <ListBox
                ref = 'listBox'
                title="资源管理"
                isHideLeft={isHideLeft}
                tableColumnData = {tableColumn}
                searchComponentData={searchComponentData}
                url = '/base/resource/list'
                rowHandles = {this.rowHandles}
                rowOperation = {this.rowOperation}
                headerOperation = {this.headerOperation}
                isRowSingle = "true"
            />
        )
    }
}
